﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Daphne.GameShared;

namespace GameEngine.PDNParser
{
    public enum enumPDNGameResult { None, Win1, Draw1, Loss1, Win2, Draw2, Loss2, DoubleForfeit };

    public static class PDNHeaderKey
    {
        public static string Event = "Event";
        public static string Site = "Site";
        public static string Date = "Date";
        public static string White = "White";
        public static string Black = "Black";
        public static string Round = "Round";
        public static string Result = "Result";
        public static string GameType = "GameType";
        public static string FENSetup = "FEN";
        
        public static string WhiteTitle = "WhiteTitle";
        public static string BlackTitle = "BlackTitle";
        public static string WhiteRating = "WhiteRating";
        public static string BlackRating = "BlackRating";
        public static string WhiteNA = "WhiteNA";
        public static string BlackNA = "BlackNA";
        public static string WhiteType = "WhiteType";
        public static string BlackType = "BlackType";

        public static string EventDate = "EventDate";
        public static string EventSponsor = "EventSponsor";
        public static string Section = "Section";
        public static string Stage = "Stage";
        public static string Board = "Board";

        public static string TimeControl = "TimeControl";
        public static string TimeControlWhite = "TimeControlWhite";
        public static string TimeControlBlack = "TimeControlBlack";
        public static string WhiteTime = "WhiteTime";
        public static string BlackTime = "BlackTime";

        public static string UTCTime = "UTCTime";
        public static string UTCDate = "UTCDate";

        public static string Annotator = "Annotator";
        public static string Author = "Author";
        public static string Publication = "Publication";
        public static string PublicationDate = "PublicationDate";
    }

    /// <summary>
    /// Syntax tree object representing PDN header
    /// </summary>
    public class PDNRawHeader
    {
        public string Key
        { get; set; }

        public string Value
        { get; set; }
    }

    
    /// <summary>
    /// Base class for GameBody syntax elements
    /// </summary>
    public abstract class PDNRawGameBodyItem
    {
    }

    /// <summary>
    /// PDN Raw Game Body item - collection of many syntax elements
    /// inherits itself from base game body item element for move variations
    /// </summary>
    public class PDNRawGameBody : PDNRawGameBodyItem
    {
        public List<PDNRawGameBodyItem> Items
        { get; set; }

        public PDNRawGameBody()
        {
            this.Items = new List<PDNRawGameBodyItem>();
        }
    }

    public enum enumPDNPositionType { Checkers, Chess };

    /// <summary>
    /// Representation of position
    /// </summary>
    public class PDNRawPosition
    {
        public enumPDNPositionType PositionType
        { get; set; }

        public string Position
        { get; set; }
    }

    /// <summary>
    /// Representation of ove in the syntax tree
    /// </summary>
    public class PDNRawMove: PDNRawGameBodyItem
    {
        public int? MoveNumber
        { get; set; }

        public List<PDNRawPosition> Positions
        { get; set; }

        public bool CaptureMove
        { get; set; }

        public string MoveStrength
        { get; set; }

        public bool EmptyMove
        { get; set; }

        public PDNRawMove()
        {
            this.Positions = new List<PDNRawPosition>();
            EmptyMove = false;
        }     
    }

    /// <summary>
    /// Move comment
    /// </summary>
    public class PDNRawComment : PDNRawGameBodyItem
    {
        public string Comment
        { get; set; }
    }

    /// <summary>
    /// FEN Setup string
    /// </summary>
    public class PDNRawFENSetupString : PDNRawGameBodyItem
    {
        public string FENSetup
        { get; set; }
    }

    /// <summary>
    /// NAG Strength
    /// </summary>
    public class PDNRawNAG : PDNRawGameBodyItem
    {
        public string NagValue
        { get; set; }
    }
    /// <summary>
    /// Syntax tree object - PDN Game
    /// </summary>
    public class PDNRawGame
    {
        public List<PDNRawHeader> Headers
        { get; set; }

        public enumGameType GameType
        { get; set; }

        public bool SuicialCheckers
        { get; set; }

        public PDNRawGameBody GameBody
        { get; set; }

        public enumPDNGameResult GameResult
        { get; set; }

        public PDNRawGame()
        {
            this.Headers = new List<PDNRawHeader>();
            GameResult = enumPDNGameResult.None;
            GameBody = new PDNRawGameBody();
        }
    }

    /// <summary>
    /// PDN Syntax Tree Main Object
    /// </summary>
    public class PDNRawGameList
    {
        public List<PDNRawGame> Games
        { get; set; }

        public PDNRawGameList()
        {
            this.Games = new List<PDNRawGame>();
        }
    }
}
